package com.example.springboot_sp.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.example.springboot_sp.common.Result;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.example.springboot_sp.service.IDictService;
import com.example.springboot_sp.entity.Dict;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 郭守军
 * @since 2022-08-22
 */
        @RestController
        @RequestMapping("/dict")
                public class DictController {

        @Resource
        private IDictService dictService;

        // 新增或者更新
        @PostMapping
        public Result save(@RequestBody Dict dict) {
                return Result.success(dictService.saveOrUpdate(dict));
                }

        @DeleteMapping("/{id}")
        public Result delete(@PathVariable Integer id) {
                return Result.success(dictService.removeById(id));
                }

        @PostMapping("/del/batch")
        public Result deleteBatch(@RequestBody List<Integer> ids) {
                return Result.success(dictService.removeByIds(ids));
                }

        @GetMapping
        public Result findAll() {
                return Result.success(dictService.list());
                }

        @GetMapping("/{id}")
        public Result findOne(@PathVariable Integer id) {
                return Result.success(dictService.getById(id));
                }

        @GetMapping("/page")
        public Result findPage(@RequestParam Integer pageNum,
        @RequestParam Integer pageSize) {
                QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
                queryWrapper.orderByDesc("id");
                return Result.success(dictService.page(new Page<>(pageNum, pageSize), queryWrapper));
                }
                }

